<?php

    /**
    * Node Controller.
    *
    * Helpful methods to make Controller.
    *
    * PHP versions 5
    * CAKEPHP versions 2.x
    * 
    * Green CMS - Content Management System and Framework Powerfull by Cakephp
    * Copyright 2012, GREEN GLOBAL CO., LTD (toancauxanh.vn)
    * 
    * CakePHP(tm) :  Rapid Development Framework (http://www.cakephp.org)
    * Copyright 2005-2011, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
    *
    * Licensed under The MIT License
    * Redistributions of files must retain the above copyright notice.
    *
    * @author        Technology Lab No.I <tech1@toancauxanh.vn>
    * @link          
    * @package       NodeType.Controller
    * @since         Green v 1.0
    * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
    */
    App::uses('ViewAppController', 'View.Controller');
    App::uses('str_utility','Vendor');   
    Class ViewController extends ViewAppController {

        /**
        * Use model class
        *
        * @var array
        */
        public $uses = array('Node.Node','Node.NodeTerm','Node.Term', 'Node.Gallery','Node.NodeType');          
        /**
        * Use model class
        *
        * @var array
        */
        public $helpers = array('Text', 'String','Js');
        public $compenents= array('RequestHandler');
        public function beforeFilter() {                          
            parent::beforeFilter();           
            if (in_array($this->request['action'], array('contact','document','comment','search','request','contact_phong','search_text_phong'))) 
            {            
                $this->Components->disable('Security');
            }               
        } 
        //------------------Page DHNN----------------//      
        public function contact() {            
            $contact = $nodeType = null;
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>Contact) 
            ));                   
           /* $this->loadModel('View.Contact');*/
            $this->loadModel('Node.Node');
            if(!empty($this->request->data)){
                $data= $this->request->data;                
                $data['Contact']['node_type_id'] = Contact;  
                $data['Contact']['user_id'] = 1;
                $data['Contact']['title'] = $data['Contact']['field_name'];                                             
                if($this->Node->save($data['Contact'])) {                    
                    $Email = $this->Components->load('Email');
                    $this->Email->smtpOptions = array(
                    'port'=>'465',
                    'timeout'=>'30',
                    'host' => 'ssl://smtp.gmail.com',
                    'username'=>'vantu06i@gmail.com',
                    'password'=>'dungcomo',
                    );
                    /*$this->Email->delivery = 'smtp';  */              
                    //$Email->template= 'View.contact';
                    $Email->subject = ('[DHNN ] '. $data['Contact']['field_name']);
                    $content= "Name: ".$data['Contact']['field_name'].'<br />'. "Email: ".$data['Contact']['field_email']."<br />"."Content: ".$data['Contact']['field_description'];
                    $Email->sendAs = 'html';
                    $Email->from = '[DHNN] <tunv@appdev.vn>';
                    $Email->to = 'tunv@appdev.vn';
                    $Email->subject = ('[Có thông tin liên hệ]'. $data['Contact']['title']);
                    //$this->set('data',$this->request->data);
                    //$Email->send($content);
                    $Email->to = $data['Contact']['field_email'];
                    $Email->subject = ('[DHNN]');
                    $content2 = __d('default','Xin chào ').$data['Contact']['field_name']."!<br /><br />.".__d('default','Your message was sent successfully.')."<br />Thanks!";
                    //$Email->send($content2);
                    $this->Session->setFlash(__d('system', 'Gửi email liên hệ thành công'),'me'); 
                    $this->redirect(array('plugin' => 'View', 'controller' => 'View', 'action' => 'contact'));
                }  
            }
            $this->set(compact('nodeType'));

        } 
        //Dang ky nhan tin
        public function register_letter($email=null)
        {
          $this->layout = 'ajax';
          $this->autoRender = false; 
          $data['Node']['title'] = '[DHNN] '.$email;
          $data['Node']['field_email'] = $email;
          $data['Node']['user_id'] = 1;          
          $data['Node']['node_type_id'] = Register_Letter;      
          $data['Node']['is_published'] = 0;
          $this->Node->unbindValidation('remove', array('title', 'enabled','node_type_id'), true);
          $this->Node->create();      
          if($this->Node->save($data['Node']))
          {
             echo 1;die(); 
          }
          echo 0;die();
           
        }
        //Gioi thieu
        public function introduction($alias=null){  
        $Term = ClassRegistry::init('Node.NodeTerm');
        $Term->Behaviors->attach('Translator');          
            if(empty($alias)){
                $introduction_general = $this->NodeTerm->find('first',array(
                    'contain'=>array('Node'=>array(
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )),                   
                   'locale'=>true,
                   'order'=>'Node.created desc',
                   'conditions'=>array('NodeTerm.term_id'=>Term_about,'Node.is_published'=>1) 
                ));                   
                $introduction_function_task = $this->NodeTerm->find('first',array(
                    'contain'=>array('Node'=>array(
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )),                   
                   'locale'=>true,
                   'order'=>'Node.created desc',
                   'conditions'=>array('NodeTerm.term_id'=>Term_task,'Node.is_published'=>1) 
                ));             
                $introduction_target = $this->NodeTerm->find('first',array(
                    'contain'=>array('Node'=>array(
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )),                   
                   'locale'=>true,
                   'order'=>'Node.created desc',
                   'conditions'=>array('NodeTerm.term_id'=>Term_target,'Node.is_published'=>1) 
                ));
                $introduction_cooperation = $this->NodeTerm->find('first',array(
                    'contain'=>array('Node'=>array(
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )),                   
                   'locale'=>true,
                   'order'=>'Node.created desc',
                   'conditions'=>array('NodeTerm.term_id'=>Term_cooperation,'Node.is_published'=>1) 
                ));                
            }
            else
            {
                $introduction_detail = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Introduction_detail),
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                ));                 
            }            
            $this->set(compact('alias','introduction_general','introduction_function_task','introduction_target','introduction_cooperation','introduction_detail'));         
        }  
        public function scientific_research($alias = null){
            $scientific_research_detail = $scientific_research = null;
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>Scientific_research) 
            )); 
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Scientific_research),
                    'limit'=>Limit_default
                );   
            }
            else
            {
                $scientific_research_detail = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Scientific_research),
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                )); 
                $scientific_research_other = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Scientific_research),
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                ));                                
            }            
            $scientific_research = $this->paginate('Node.Node');
            $this->set(compact('alias','scientific_research','scientific_research_detail','scientific_research_other','nodeType'));            
        } 
        public function recruitment($alias = null){
            $recruitment_detail = $recruitment = null; 
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>Recruitment) 
            )); 
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Recruitment),
                    'limit'=>Limit_default
                );   
            }
            else
            {
                $recruitment_detail = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Recruitment),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                )); 
                $recruitment_detail_other = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Recruitment),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                ));                                
            }            
            $recruitment = $this->paginate('Node.Node');
            $this->set(compact('alias','nodeType','recruitment_detail','recruitment','recruitment_detail_other'));            
        }    
        public function education($alias = null){
            $education = $education_detail = null; 
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>Education) 
            )); 
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Education),
                    'limit'=>Limit_default
                );   
            }
            else
            {
                $education_detail = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Education),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                )); 
                $education_other = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Education),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                ));                                
            }            
            $education = $this->paginate('Node.Node');
            $this->set(compact('alias','nodeType','education','education_detail','education_other'));            
        }  
        public function student_affairs($alias = null){
            $student_affairs = $student_affairs_detail = null; 
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>Student_affairs) 
            )); 
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Student_affairs),
                    'limit'=>Limit_default
                );   
            }
            else
            {
                $student_affairs_detail = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Student_affairs),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                )); 
                $student_other = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Student_affairs),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                ));                                
            }            
            $student_affairs = $this->paginate('Node.Node');
            $this->set(compact('alias','nodeType','student_affairs','student_affairs_detail','student_other'));            
        } 
        public function international_cooperation($alias = null){
            $international_cooperation = $international_cooperation_detail = null; 
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>International_cooperation) 
            )); 
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>International_cooperation),
                    'limit'=>Limit_default
                );   
            }
            else
            {
                $international_cooperation_detail = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>International_cooperation),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                )); 
                $international_cooperation_other = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>International_cooperation),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                ));                                
            }           
            $international_cooperation = $this->paginate('Node.Node');
            $this->set(compact('alias','nodeType','international_cooperation','international_cooperation_detail','international_cooperation_other'));            
        } 
        public function library($alias = null){
            $library = $library_detail = null; 
            $nodeTypeID = -1;    
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>Library) 
            )); 
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Library),
                    'limit'=>Limit_default
                );   
            }
            else
            {
                $library_detail = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Library),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                )); 
                $library_other = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Library),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                ));                                
            }       
            $library = $this->paginate('Node.Node');
            $this->set(compact('alias','nodeType','library','library_detail','library_other'));            
        }         
        public function document($alias = null){
            /*if ($this->request->is('ajax')) {
              $this->layout = 'ajax';
            }  */
            $nodeTypeID = -1;              
            $term_id = $this->Session->read('term_id');  
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>Document) 
            ));
            $type_document = $this->Term->find('list',array(
               'locale'=>true,
               'conditions'=>array('Term.type_id'=>Document),
               'fields'=>array('Term.id','Term.name') 
            ));
            if(!empty($term_id)){
               $this->request->data['Node']['type_document'] = $term_id;  
            }                                                                  
            if(!empty($this->request->data)){
                $data = $this->request->data;
                if(!empty($data['Node']['type_document'])){
                    $term_id = intval($data['Node']['type_document']);
                    $this->Session->write('term_id',$term_id);                                        
                    $this->paginate = array(
                        'contain'=>array('Node'=>array(
                            'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                        )),
                        'limit'=>10,                   
                       'locale'=>true,
                       'order'=>'Node.created desc',
                       'conditions'=>array('NodeTerm.term_id'=>$term_id,'Node.is_published'=>1) 
                    );
                    $document = $this->paginate('Node.NodeTerm');                    
                }
            }
            else
            {
                    $this->paginate = array(
                        'locale'=>true,
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.field_attach_file','Node.field_number_signital','Node.node_type_id','Node.created','Node.updated'),
                        'order'=>'Node.created desc',
                        'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Document),
                        'limit'=>1
                    );
                    $document = $this->paginate('Node.Node');                    
            }            
            $this->set(compact('nodeType','type_document','document'));            
        }        
        public function news_detail($alias = null){                        
            $news_detail = $news = $comment= null; 
            $nodeTypeID = -1;    
            $id = -1;
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>News) 
            ));  
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>News),
                    'limit'=>Limit_default
                );
                $news = $this->paginate('Node.Node');                
            }
            else
            {
                    $news_detail = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>News),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                )); 
                if(!empty($news_detail)){$id = $news_detail['Node']['id'];}                                        
                    $news_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>News),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    )); 
               $this->loadModel('View.Comment');
               $comment = $this->Comment->find('all',array(
                'conditions'=>array('Comment.node_id'=>$news_detail['Node']['id'],'Comment.status'=>1),
                'order'=>'Comment.created desc'                
               ));                                                       
            }                                   
            $this->set(compact('alias','nodeType','news_other','news_detail','news','id','comment'));            
        }
        public function comment(){
            $this->autoRender = false;
            $this->loadModel('View.Comment');
            if(!empty($this->request->data)){
               $data = $this->request->data;
               $this->Comment->create();
               $this->Comment->save($data);
            }            
        }
        public function question($alias=null){
            $news_detail = $news = $user = null; 
            $nodeTypeID = -1;    
            $user = $this->Auth->user();           
            if(!empty($user)){
                $fullname = $user['fullname'];
            }
            $id = -1;              
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.field_attach_file','Node.field_name','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Question),
                    'limit'=>16
                );
                $question = $this->paginate('Node.Node');                             
            }
            else
            {
                    $question_detail = $this->Node->find('first',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Question),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.field_attach_file','Node.field_name','Node.field_email','Node.created','Node.updated'),
                    ));
                                         
                    $question_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Question),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'limit'=>Limit_default,
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                                                                            
            }                                   
            $this->set(compact('alias','question','question_detail','question_other','user'));    
        }
        public function search($keyword=null){
           $site_current = Configure::read('App.themes.site_current');
           $subsite_id = -1;
           $router = null;
           if(!empty($site_current)){
             $subsite_id = $site_current['sub_sites']['id'];   
           }
           $array_nodeType = array(News,Education,Student_affairs,Scientific_research,Notice,International_cooperation);           
           $node_type = $this->NodeType->find('list',array(
            'conditions'=>array('NodeType.sub_site'=>$subsite_id,'NodeType.id'=>$array_nodeType),            
            'locale'=>true
           ));          
           if(!empty($node_type)){
              $node_type = array_keys($node_type); 
           }
           $keyword_session = $this->Session->read('keyword_session');
           if(!empty($keyword_session)){
              $keyword = $keyword_session; 
           } 
           if(!empty($this->request->data)){
             $keyword = $this->request->data['Contact']['keyword'];
             $this->Session->write('keyword_session',$keyword);  
           }                       
           $this->paginate = array(
             'locale'=>true,
             'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.node_type_id','Node.created','Node.updated','Node.field_attach_file','Node.field_image_default'),
             'conditions'=>array('Node.title LIKE'=>'%'.trim($keyword).'%','Node.node_type_id'=>$node_type),
             'limit'=>Limit_default
           );           
           $search = $this->paginate('Node.Node');
           if(!empty($search)){               
               foreach($search as $k=>$v){
                    $router = $this->parseAction($v['Node']['node_type_id'],$v['Node']['alias']);
                    $search[$k]['Node']['action'] = $router;   
               }                              
           }           
           $this->set(compact('search'));
        }
        public function notice_detail($alias = null){                        
            $notice_detail = $notice = $notice_other = null; 
            $nodeTypeID = -1;    
            $id = -1;
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>Notice) 
            ));  
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Notice),
                    'limit'=>Limit_default
                );
                $notice = $this->paginate('Node.Node');                
            }
            else
            {
                    $notice_detail = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Notice),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                ));
                    //debug($alias);exit; 
                if(!empty($notice_detail)){$id = $notice_detail['Node']['id'];}                                        
                    $notice_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Notice),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                                            
            }                                   
            $this->set(compact('alias','nodeType','notice_other','notice_detail','notice','id'));            
        }        
        public function image_active($alias = null){                                
            $notice_detail = $notice = $notice_other = null; 
            $nodeTypeID = -1;    
            $id = -1;
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>Image_active) 
            ));                          
            if(empty($alias))
            {
                $this->paginate = array(
                    'locale'=>true,
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    'order'=>'Node.created desc',
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>Image_active),
                    'limit'=>Limit_default
                );
                $notice = $this->paginate('Node.Node');                
            }
            else
            {
                    $notice_detail = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>Image_active),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),                    
                ));                                 
                if(!empty($notice_detail)){$id = $notice_detail['Node']['id'];}                                        
                    $notice_other = $this->Node->find('all',array(
                        'conditions'=>array('Node.is_published'=>1,'Node.alias <>'=>$alias,'Node.node_type_id'=>Image_active),
                        'locale'=>true,
                        'order'=>'Node.created desc',
                        'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated'),
                    ));                                            
            }                                   
            $this->set(compact('alias','nodeType','notice_other','notice_detail','notice','id'));            
        }
        public function training_lookup_detail($alias=null,$node_type_id=null){
            $training_lookup_detail =  null; 
            $nodeTypeID = -1;    
            $id = -1;
            $nodeType = $this->NodeType->find('first',array(
               'locale'=>true,
               'fields'=>array('NodeType.id','NodeType.name'),
               'conditions'=>array('NodeType.id'=>$node_type_id) 
            ));            
            $training_lookup_detail = $this->Node->find('first',array(
                'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_type_id),
                'locale'=>true,
                'order'=>'Node.created desc',
                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.field_image_default','Node.created','Node.updated')
            ));
           $this->set(compact('nodeType','training_lookup_detail'));                   
        }
        public function news_rss()
        {
            $this->layout = false;
            $router_action = null;
            $link = $_SERVER['SERVER_NAME'];  
            $newRss = $this->Node->find('all',array(
                'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>array(News,Education,Student_affairs,Scientific_research,International_cooperation)),
                'locale'=>true,
                'order'=>'Node.created desc',
                'fields'=>array('Node.id','Node.title','Node.alias','Node.field_description','Node.field_body','Node.node_type_id','Node.field_image_default','Node.created','Node.updated')
            ));
            if(!empty($newRss)){
                foreach($newRss as $k=>$v){
                    $node_type_id = $v['Node']['node_type_id'];
                    $router_action = $this->parseAction($v['Node']['node_type_id'],$v['Node']['alias']);                   
                    $newRss[$k]['Node']['router_action'] = $router_action;                     
                }               
            }                          
            $this->set(compact('newRss','link'));        
        } 
        public function request(){                     
             $this->layout= 'ajax';
             $this->autoRender = false;
             if(!empty($this->request->data)){
                $data = $this->request->data;
                if($data['Request']['captcha']!=$this->Session->read('captcha')){
                    echo 0;exit;
                }else{
                    $this->Node->create();
                    $data['Node']['title'] = $data['Request']['title'] ; 
                    $data['Node']['field_name'] = $data['Request']['field_name'];
                    $data['Node']['field_address'] = $data['Request']['field_address']; 
                    $data['Node']['field_email'] = $data['Request']['field_email'];
                    $data['Node']['node_type_id'] = 122; 
                    $data['Node']['user_id'] = 1;
                    $data['Node']['is_published'] = 0;
                    if($this->Node->save($data['Node'])){ echo 1; exit;}                   
                }
             }else{echo 0;exit;}             
        }
        public function parseAction($node_type_id = null,$alias=null){
            $action = null;
            switch($node_type_id){
               case News:$action = 'news_detail';break;                        
               case Education:$action = 'education';break;                        
               case Student_affairs:$action = 'student_affairs';break;                        
               case Scientific_research:$action = 'scientific_research';break;                                               
               case Notice:$action = 'notice_detail';break; 
               case 'International_cooperation': $action = 'international_cooperation';
            }
            $router = array('plugin'=>'View','controller'=>'View','action'=>$action,$alias);            
            return $router; 
        }
        public function download($id=null,$node_type_id=null)
        {
            Configure::write('debug',2);
            $this->loadModel('Node.Node');        
            $this->autoRender = false;
            if(!empty($id))
            {                
                $book = $this->Node->find('first',array(
                    'conditions'=>array('Node.id'=>$id),
                    'fields'=>array('Node.id','Node.field_attach_file')
                ));                                      
                if(!empty($book))
                {
                    $file_path= WWW_ROOT.'img/'.$book['Node']['field_attach_file'];
                    $params= explode("/", $book['Node']['field_attach_file']);
                    $file_name= $params[count($params)-1];                              
                    if(is_file($file_path)){                    
                        header('Content-type: application/octet-stream');
                        header('Content-disposition: attachment; filename="'.$file_name.'"');
                        header('Content-length: ' . filesize($file_path));              
                        echo file_get_contents($file_path);                        
                    } 
                }   
            }            
        } 
      
        //-------------------End Page DHNN----------------
        public function news_detail_phong($alias = null){
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>6,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
           if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_body','Node.created'),
                )); 
           $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
           );           
           $other_contents = $this->paginate('Node.Node');

           
           }else{
           $contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_description','Node.field_image','Node.created','Node.alias'),
                    'limit'=>7
                )); 
            if(!empty($contents[6]['Node']['created'])){
           $other_contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                )); 
                }               
           }
           $this->set(compact('alias','contents','other_contents'));   
        }
        public function hr_phong($alias = null){
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types_id_hrs = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>2,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                )); 
        $contents = $this->Node->find('first',array(
                'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_hrs['NodeType']['id']),
                'locale'=>true,
                'order'=>'Node.created desc',
                'fields'=>array('Node.title','Node.field_body'),
            ));     
        $this->set(compact('alias','contents','other_contents'));                   
        }
        public function assign_job_detail($alias = null){
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types_id_hrs = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>5,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                )); 
        $contents = $this->Node->find('first',array(
                'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_hrs['NodeType']['id']),
                'locale'=>true,
                'order'=>'Node.created desc',
                'fields'=>array('Node.field_week','Node.field_body','Node.field_description'),
            ));     
        $this->set(compact('alias','contents','other_contents'));      
        }
        public function document_detail_phong(){
            $site_current = Configure::read('App.themes.site_current');
            $id_sub_site = $site_current['sub_sites']['id'];    
            $node_types_id = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>3,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                )); 
           $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_description','Node.field_file','Node.created'),
                    'limit'=>11,
           );           
           $contents = $this->paginate('Node.Node');
  
           $this->set(compact('contents','other_contents'));         
        }
        public function palace_detail_phong($alias = null){
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>4,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
           if(!empty($alias)){
           $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_body','Node.created'),
                )); 
           $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
           );           
           $other_contents = $this->paginate('Node.Node');

           
           }else{
           $contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_file','Node.field_description','Node.field_image','Node.created','Node.alias'),
                    'limit'=>7
                )); 
            if(!empty($contents[6]['Node']['created'])){
           $other_contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                )); 
                }                 
           }
           $this->set(compact('alias','contents','other_contents'));   
        } 
        public function education_program_phong($alias = null){
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>15,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
           if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_body','Node.created'),
                )); 
           $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
           );           
           $other_contents = $this->paginate('Node.Node');

           
           }else{
           $contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_description','Node.field_image','Node.created','Node.alias'),
                    'limit'=>7
                )); 
            if(!empty($contents[6]['Node']['created'])){
           $other_contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                )); 
                }                
           }
           $this->set(compact('alias','contents','other_contents'));   
        }  
        public function education_plan_phong($alias = null){
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>16,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
           if(!empty($alias)){
                $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_body','Node.created'),
                )); 
           $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
           );           
           $other_contents = $this->paginate('Node.Node');

           
           }else{
           $contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                     'fields'=>array('Node.title','Node.field_file','Node.field_description','Node.field_image','Node.created','Node.alias'),
                    'limit'=>7
                )); 
            if(!empty($contents[6]['Node']['created'])){
           $other_contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                )); 
                }              
           }
           $this->set(compact('alias','contents','other_contents'));   
        }   
        public function admission_detail_phong($alias = null){
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>17,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
           if(!empty($alias)){
           $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_body','Node.created'),
                )); 
           $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
           );           
           $other_contents = $this->paginate('Node.Node');

           
           }else{
           $contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_file','Node.field_description','Node.field_image','Node.created','Node.alias'),
                    'limit'=>7
                )); 
            if(!empty($contents[6]['Node']['created'])){
           $other_contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                )); 
                }                 
           }
           $this->set(compact('alias','contents','other_contents'));   
        }  
        public function cooperation_detail_phong($alias = null){
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>18,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
           if(!empty($alias)){
           $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_body','Node.created'),
                )); 
           $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
           );           
           $other_contents = $this->paginate('Node.Node');

           
           }else{
           $contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_file','Node.field_description','Node.field_image','Node.created','Node.alias'),
                    'limit'=>7
                )); 
            if(!empty($contents[6]['Node']['created'])){
           $other_contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                )); 
                }               
           }
           $this->set(compact('alias','contents','other_contents'));   
        } 
    public function about_phong(){
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>19,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
           $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_body'),
                    'limit'=>7
                ));  
           $this->set(compact('alias','contents','other_contents'));                 
    }  
        public function notice_phong($alias = null){
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types_id_news = $this->NodeType->find('first',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>1,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'locale'=>true,
                    'fields'=>array('id'),
                ));
           if(!empty($alias)){
           $contents = $this->Node->find('first',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.alias'=>$alias,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_body','Node.created'),
                )); 
           $this->paginate = array(
                    'conditions'=>array('Node.is_published'=>1,'Node.id <>'=>$contents['Node']['id'],'Node.created <'=>$contents['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
           );           
           $other_contents = $this->paginate('Node.Node');

           
           }else{
           $contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.field_file','Node.field_description','Node.field_image','Node.created','Node.alias'),
                    'limit'=>7
                )); 
            if(!empty($contents[6]['Node']['created'])){
           $other_contents = $this->Node->find('all',array(
                    'conditions'=>array('Node.is_published'=>1,'Node.created <'=>$contents[6]['Node']['created'],'Node.node_type_id'=>$node_types_id_news['NodeType']['id']),
                    'locale'=>true,
                    'order'=>'Node.created desc',
                    'fields'=>array('Node.title','Node.alias','Node.created'),
                    'limit'=>4
                )); 
                }                
           }
           $this->set(compact('alias','contents','other_contents'));   
        } 
     public function contact_phong() {         
         $this->loadModel('View.Contact');
         $this->loadModel('View.Node');
         $site_current = Configure::read('App.themes.site_current');
         if(!empty($this->request->data)){
            $data= $this->request->data;
 
            $data['Contact']['sub_site'] = $site_current['sub_sites']['id'];  
            
            if($data['Contact']['captcha']!=$this->Session->read('captcha'))
                {
                   $this->Session->setFlash(__d('default', 'Xin nhập mã xác nhận'),'error');
               } 
               else{                      
            if($this->Contact->save($data['Contact'])) {
                 
                 $Email = $this->Components->load('Email');
                 $Email->subject = ('[Thông tin liên hệ] '. $data['Contact']['name']);
                 $content= "Họ & tên : ".$data['Contact']['name'].'<br />'
                            ."Địa chỉ : ".$data['Contact']['address'].'<br />'
                            . "Số điện thoại : ".$data['Contact']['phone']."<br />"
                            . "Chủ đề : ".$data['Contact']['title']."<br />"
                            . "Nội dung : ".$data['Contact']['content']."<br />";
                 $Email->sendAs = 'html';
                 $Email->from = 'khoahna@greenglobal.vn';
                 $Email->to = 'khoahna@greenglobal.vn'; //$site_current['sub_sites']['email']
                 $Email->subject = ('[Có thông tin liên hệ]'. $data['Contact']['title']);
                 //$this->set('data',$this->request->data);
                 //$Email->send($content);
                   $this->Session->setFlash(__d('default', 'Gửi thông tin liên hệ thành công'),'flash_custom');
                    $this->redirect('/lien-he-phong');                    
                 
            }
            else {
                    $this->Session->setFlash(__d('default', 'Xin vui lòng điền đầy đủ thông tin'),'error');
                                    
                }  
         }
        }
    } 
        public function captcha_image()
        {
            App::uses('captcha','Vendor/captcha');
            $captcha = new captcha();
            $captcha->show_captcha();
        }
        public function captcha() 
        {
            $this->Captcha->show();
        } 
    public function search_text_phong()
    { 
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types = $this->NodeType->find('list',array(
                    'conditions'=>array('NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'fields'=>array('id'),
                ));
        $node_type_actions = $this->NodeType->find('all',array(
                    'conditions'=>array('NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'fields'=>array('action'),
                ));

        $node = null;
        $session_text = null;
        if($this->request->is('post'))
       {
           $data = $this->request->data['search_text_phong'];
              
           $list_node = null;
           //$this->loadModel('Node.NodeTerm');
           $conds =array('Node.is_published'=>1,'Node.node_type_id'=>$node_types,"NOT" => array( "Node.node_type_id" => array(165)));
           if(!empty($data))
           {
            $key =  $data['key'];
            $session_text['key'] = $key;
            if((isset($data['key']))&&(!empty($data['key'])))
               {
             $conds = array_merge($conds,array( 
                      'OR' => array( 
                        array('Node.title LIKE' => '%'.$key.'%'),    
                      ) 
                    )); 
             $this->paginate  = array(
                        'locale'=>true,
                        'conditions'=>$conds,
                        'fields'=>array('Node.id','Node.alias','Node.title','Node.node_type_id','Node.field_description','Node.field_file','Node.created'),
                        'order' =>'Node.created desc',
                        'limit'=>10,               
                        );
                $contents = $this->paginate('Node');                                                                          
               }
                    
           }
       }
       $this->Session->write('session_text',$session_text);
		      
        $this->set(compact('alias','contents','key','node_type_actions')); 

   }         
    public function search_document_phong()
    { 
        $site_current = Configure::read('App.themes.site_current');
        $id_sub_site = $site_current['sub_sites']['id'];
        $node_types = $this->NodeType->find('list',array(
                    'conditions'=>array('NodeType.kind_node_type_id'=>3,'NodeType.sub_site'=>$id_sub_site),
                    'recursive'=>false,
                    'fields'=>array('id'),
                ));


        $node = null;
        $session_document = null;
        if($this->request->is('post'))
       {
           $data = $this->request->data['search_document_phong'];
              
           $list_node = null;
           //$this->loadModel('Node.NodeTerm');
           $conds =array('Node.is_published'=>1,'Node.node_type_id'=>$node_types);
           if(!empty($data))
           {
            $key =  $data['key'];
            $session_document['key'] = $key;
            if((isset($data['key']))&&(!empty($data['key'])))
               {
             $conds = array_merge($conds,array( 
                      'OR' => array( 
                        array('Node.title LIKE' => '%'.$key.'%'),    
                      ) 
                    )); 
             $this->paginate  = array(
                        'locale'=>true,
                        'conditions'=>$conds,
                        'fields'=>array('Node.id','Node.alias','Node.title','Node.node_type_id','Node.field_description','Node.field_file','Node.created'),
                        'order' =>'Node.created desc',
                        'limit'=>10,               
                        );
                $contents = $this->paginate('Node');  
                                                                     
               }
                    
           }
       }
       $this->Session->write('session_document',$session_document);
		      
        $this->set(compact('alias','contents','key2','node_type_actions')); 

   }                                    
}
?>